import axios from 'axios'
import Qs from 'Qs'

// 超时时间
axios.defaults.timeout = 30000
if (window.location.href.indexOf('shiba.com') >= 0) {
  axios.defaults.baseURL = 'https://www.shiba.com'
} else {
  axios.defaults.baseURL = 'http://localhost:7001'
}

axios.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'
// 请求时的拦截
axios.interceptors.request.use(function (config) {
  config.data = Qs.stringify(config.data)
  return config
}, function (error) {
  return Promise.reject(error)
})

// 响应时拦截
axios.interceptors.response.use(function (response) {
  return response.data
}, function (error) {
  return Promise.reject(error)
})

export default axios
